package com.zmn.plat.admin.controller.part.category.map;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.VtDTO;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.admin.controller.part.PartBaseController;
import com.zmn.plat.model.vo.part.PartCategoryMapVO;

/**
 * 类描述： PartCategoryMapListController 产品配件分类关联
 *
 * @author DaiZhichao
 * @since 2018/12/13 16:46
 */
@Controller
@RequestMapping("/part/category/map")
public class PartCategoryMapListController extends PartBaseController {

    private Logger logger = LoggerFactory.getLogger(PartCategoryMapListController.class);

    /**
     * 描述: [跳转] 跳转到 产品配件分类关联
     *
     * @author DaiZhichao
     * @since 2018/12/13 16:54
     */
    @RequestMapping("/list")
    @RequiresPermissions("/part/category/map/list.action")
    public String partCategoryMapList(Model model) {
        List<VtDTO> partCategorySimpleList = partCategoryService.getPartCategorySimpleList(GlobalConsts.TOP_ID);
        List<VtDTO> baseCategorySimpleList = baseCategoryService.listByParentId(GlobalConsts.TOP_ID);

        model.addAttribute("partCategorySimpleList", partCategorySimpleList);
        model.addAttribute("baseCategorySimpleList", baseCategorySimpleList);
        return "part/category/map/list";
    }

    /**
     * 描述: [跳转] 跳转到 产品配件分类关联 添加页面
     *
     * @author DaiZhichao
     * @since 2018/12/13 16:54
     */
    @RequestMapping("/addEdit")
    @RequiresPermissions("/part/category/map/addEdit.action")
    public String addEdit(@RequestParam(value = "mapId", required = false) Integer mapId, Model model) {

        PartCategoryMapVO categoryMapVO =
            NumberUtil.isNullOrZero(mapId) ? new PartCategoryMapVO() : partCategoryMapService.findByKey(mapId);
        List<VtDTO> partCategorySimpleList = partCategoryService.getPartCategorySimpleList(GlobalConsts.TOP_ID);
        List<VtDTO> baseCategorySimpleList = baseCategoryService.listByParentId(GlobalConsts.TOP_ID);

        model.addAttribute("partCategorySimpleList", partCategorySimpleList);
        model.addAttribute("baseCategorySimpleList", baseCategorySimpleList);
        model.addAttribute("categoryMap", categoryMapVO);
        return "part/category/map/addedit";
    }

}
